package com.antifake;

import java.util.Hashtable;

import com.antifake.impl.StringCodeGenerator;

public class CodeGeneratorFactory {
	
	private static Hashtable generatorTable = new Hashtable();
	
	static {
		generatorTable.put(String.class, StringCodeGenerator.class);
	}
	public static CodeGenerator createByType(Class<?> clazz) {
		Class genClazz = (Class) generatorTable.get(clazz);
		if(genClazz == null) {
			throw new IllegalArgumentException("Fail to create CodeGenerator, because can't found ClassType[" + clazz.getName() + "] ");
		}
		try {
			return (CodeGenerator) genClazz.newInstance();
		} catch (Throwable e) {
			throw new CodeGeneratorCreateException(e);
		}
	}
}
